                                                                                                                                                        package DAL;

        import java.util.*;
        
        import DBUtil.SQLUtil;
        
        public class Rank {

		//获取比赛记录表信息列表
		public List<Object> getEntity()
		{
			String sqlCmd="select *from V_Rank";
			return DBUtil.SQLUtil.executeQuery(sqlCmd, null);//执行查询操作executeQuery
		}
            
               //获取分页后比赛记录表信息列表
		public List<Object> getEntity(int page)
		{
			int size=(page-1)*15;
			String sqlCmd="select *from V_Rank limit "+size+",15";
			return DBUtil.SQLUtil.executeQuery(sqlCmd, null);//执行查询操作executeQuery
		}
                
               //根据查询条件sqlWhere获取分页后比赛记录表信息列表
		public List<Object> getEntityByWhere(String sqlWhere,int page)
		{
			int size=(page-1)*15;
			String sqlCmd="select *from V_Rank where "+sqlWhere+" limit "+ size+",15";
			return DBUtil.SQLUtil.executeQuery(sqlCmd, null);//执行查询操作executeQuery
        }
        
        //删除比赛记录表信息
        public int deleteEntity(String rankId)
        {
            String sqlCmd="delete from Rank where rankId='"+rankId+"'";
            return DBUtil.SQLUtil.executeNonQuery(sqlCmd, null);//执行非查询操作executeNonQuery
        }
        
        //删除比赛最高记录
        public int deleteItem(String MathId)
        {
            String sqlCmd="delete from Rank where MathId='"+MathId+"'";
            return DBUtil.SQLUtil.executeNonQuery(sqlCmd, null);//执行非查询操作executeNonQuery
        }
        
        //根据比赛记录表编号获取比赛记录表信息
        public List<Object> getEntityById(String rankId)
        {
            String sqlCmd="select *From V_Rank where rankId='"+rankId+"'";
            return DBUtil.SQLUtil.executeQuery(sqlCmd, null);//执行查询操作executeQuery
        }
        
        //更新比赛记录表信息
        public int updateEntity(String rankId,String mathId,String playerId,String score)
        {
            String sqlCmd="Update Rank set mathId='" + mathId + "',playerId='" + playerId + "',score='" + score + "' where rankId='"+rankId+"'";
            return SQLUtil.executeNonQuery(sqlCmd, null);
        }
        
        //插入比赛记录表信息
        public int insertEntity(String rankId,String mathId,String playerId,String score)
        {
            String sqlCmd="Insert into Rank values('" + rankId + "','" + mathId + "','" + playerId + "','"+score+"')";
            return SQLUtil.executeNonQuery(sqlCmd, null);
        }
        
        //检查插入主键是否重复
        public boolean checkExist(String rankId)
        {
            String sqlCmd="select count(*) from V_Rank where rankId='"+rankId+"'";
            if(1==Integer.parseInt(SQLUtil.excuteScalar(sqlCmd, null).toString()) )
            {
                return true;
            }
            return false;
        }

		//获取分页总数
		public Object getPageCount()
		{
			String sqlCmd="SELECT CEIL( COUNT(*)/15.0) FROM V_Rank ";
			return SQLUtil.excuteScalar(sqlCmd, null);
		}

		//根据查询条件获取分页总数
		public Object getPageCountByWhere(String sqlWhere)
		{
			String sqlCmd="SELECT CEIL( COUNT(*)/15.0) FROM V_Rank where "+sqlWhere;
			return SQLUtil.excuteScalar(sqlCmd, null);
		}
            
        }
